package cn.boyu;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyGenerator {
    public static void main(String[] args) {
        //代码生成器对象
        AutoGenerator ag = new AutoGenerator();

        //全局配置(生成代码路径，命名规则等一些列)
        GlobalConfig gc = new GlobalConfig();
        String path = System.getProperty("user.dir");
        System.out.println(path+"/src/main/java");
        gc.setOutputDir(path+"/src/main/java");
        //配置生成类的名字
        gc.setMapperName("%sMapper");
        gc.setServiceName("I%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setControllerName("%sController");
        //设置代码作者
        gc.setAuthor("yn");
        gc.setIdType(IdType.AUTO);
        ag.setGlobalConfig(gc);

        //设置数据源
        DataSourceConfig ds = new DataSourceConfig();
        ds.setDriverName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://47.94.7.215:3306/smart-energy");
        ds.setUsername("smart-energy");
        ds.setPassword("123456");
        ag.setDataSource(ds);

        //包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("cn.boyu");
        ag.setPackageInfo(pc);

        //策略配置（驼峰式配置）
        StrategyConfig sc = new StrategyConfig();
        sc.setNaming(NamingStrategy.underline_to_camel);
        sc.setColumnNaming(NamingStrategy.underline_to_camel);
        ag.setStrategy(sc);

        //执行代码生成器，生成代码
        ag.execute();
    }



}
